import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {UserInfo} from "../../modals/basic.modal";
import {AlertComponent} from "../../unit/alert";

@Component({
    selector: 'app-register',
    templateUrl: './register.page.html',
    styleUrls: ['./register.page.scss'],
})
export class RegisterPage implements OnInit {
    formData: UserInfo;
    checkedClause: boolean;
    constructor(
        private route: Router,
        private activateInfo: ActivatedRoute,
        private alertComponent: AlertComponent,
    ) {
    }

    ngOnInit() {
        this.formData = {
            phone: '',
            verification: '',
            type: '',
            password: '',
            isRead: false
        };
        this.activateInfo.queryParamMap.subscribe((res: any) => {
            this.formData.type = res.params.type;
        });
    }

    getRegister() {
        if (!this.checkedClause) {
            this.alertComponent.presentAlert('请隐私政策和阅读服务协议').then();
            return;
        }
        this.goToPage('login');
    }

    checkClause(){
        this.checkedClause = !this.checkedClause;
    }

    goToPage(url) {
        this.route.navigate([`/${url}`]).then();
    }

}
